"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FairyEditor = CS.FairyEditor;
const System = CS.System;
const puerts_1 = require("puerts");
const SG_1 = require("./SG");
const App = FairyEditor.App;
class ToolMgr {
    /**获取选中目标数量 */
    static getSelectedTargetCount() {
        let items = App.activeDoc.inspectingTargets;
        let index = 0;
        try {
            while ((items.get_Item(index) != null)) {
                index++;
            }
        }
        catch (e) {
            return index;
        }
        return index;
    }
    /**获取UBB Url文本 */
    static getUBBUrl(url, titile) {
        return `[url=` + `${url}]${titile}[/url]`;
    }
    /**UBB file文本 */
    static getUBBFile(data) {
        let a = `[url=${ToolMgr.getFilePath(data)}]`;
        let b = this.getAbsPackageItemPath(data);
        let c = "[/url]";
        return a + b + c;
    }
    /**获取packageItem的File路径 不带后缀 */
    static getFilePath(data) {
        return `file://${ToolMgr.getAbsPackageItemPath(data)}${ToolMgr.getAssetType(data)}`;
    }
    /**获取packageItem的绝对路径 不带后缀 */
    static getAbsPackageItemPath(data) {
        return `${App.project.basePath}\\assets\\${data.owner.name}${data.path}${data.name}`;
    }
    /**获取资源类型的后缀名 */
    static getAssetType(asset) {
        switch (asset.type) {
            case FairyEditor.FPackageItemType.IMAGE:
                return ".png";
            case FairyEditor.FPackageItemType.ATLAS:
                return ".jpg";
            case FairyEditor.FPackageItemType.SPINE:
                return ".json";
        }
    }
    /**拼接fgui url */
    static joinUrl(pkg, res) {
        return `ui://${pkg}/${res}`;
    }
    /**创建泛型List */
    static createGenericList(t) {
        let List = puerts_1.$generic(System.Collections.Generic.List$1, t);
        let list = new List();
        return list;
    }
    /**创建泛型字典 */
    static createGenericDictionary(t, k) {
        let Dictionary = puerts_1.$generic(System.Collections.Generic.Dictionary$2, t, k);
        let dictionary = new Dictionary();
        return dictionary;
    }
    //#region IO
    /**加载Json文件 */
    static loadJson(path) {
        if (System.IO.File.Exists(path) == false) {
            return null;
        }
        let f = System.IO.File.ReadAllText(path);
        return JSON.parse(f);
    }
    /**保存Json文件 */
    static writerJson(path, msg) {
        let config = JSON.stringify(msg);
        System.IO.File.WriteAllText(path, config);
    }
    /**写入配置 */
    static saveConfig(path) {
        let config = JSON.stringify(SG_1.default.config);
        System.IO.File.WriteAllText(path, config);
    }
}
exports.default = ToolMgr;
